import 'package:flutter/material.dart';

class IndexPage1 extends StatefulWidget {
  @override
  _IndexPage1State createState() => _IndexPage1State();
}

class _IndexPage1State extends State<IndexPage1> {

  static const citys = ['深圳', '广州', '湖南', '湛江', '北京', '上海', '杭州'];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('demo'),
      ),
      body: Container(
        child: GridView.count(
          mainAxisSpacing: 5,
          crossAxisSpacing: 5,
          crossAxisCount: 2,
          children: _buildList(),
        ),
      ),
    );
  }

  List<Widget> _buildList() {
    return citys.map((city) => _item(city)).toList();
  }

  Widget _item(String city) {
    return Container(
      height: 60,
      decoration: BoxDecoration(color: Colors.teal),
      child: Center(
        child: Text(city, style: TextStyle(color: Colors.white, fontSize: 26),),
      ),
    );
  }


}
